﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using HitachiLib.HitachiServiceRef;

namespace HitachiLib.Data
{
    public class Resource
    {
        public const int ScheduleAccess = 0x01;
        public const int ManageAccess = 0x02;

        ResourceData data;
        private Dictionary<int, Resource> children = new Dictionary<int, Resource>();
        private Resource parent;

        private static Dictionary<int, Resource> s_map = new Dictionary<int,Resource>();

        public static Resource GetUnique(ResourceData rd)
        {
            if (s_map.ContainsKey(rd.ID))
            {
                return s_map[rd.ID];
            }
            Resource r = new Resource();
            r.data = rd;
            s_map.Add(rd.ID, r);
            return r;
        }

        public Dictionary<int, Resource> Children
        {
            get { return children; }
        }

        public Resource Parent
        {
            get { return parent; }
            set { parent = value; }
        }

        public ResourceData Data
        {
            get { return data; }
        }
        public int Id
        {
            get { return Data.ID; }
        }

        public void AddChild(Resource child)
        {
            if (children.ContainsKey(child.Data.ID))
            {
                return;
            }
            children.Add(child.Data.ID, child);
            child.parent = this;
        }
    }
}
